package com.zhaoxi.project.wms.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zhaoxi.framework.aspectj.lang.annotation.Log;
import com.zhaoxi.framework.aspectj.lang.enums.BusinessType;
import com.zhaoxi.project.wms.domain.WmsProductStock;
import com.zhaoxi.project.wms.service.impl.WmsProductStockServiceImpl;
import com.zhaoxi.framework.web.BaseService;
import com.zhaoxi.framework.web.PageData;
import com.zhaoxi.common.utils.poi.ExcelUtil;
import com.zhaoxi.framework.web.page.TableDataInfo;

/**
 * 库存数量Controller
 *
 * @author zhaoxi
 * @date 2023-07-22
 */
@RestController
@RequestMapping("/wms/stock22")
public class WmsProductStockController extends BaseService {
    @Autowired
    private WmsProductStockServiceImpl wmsProductStockService;

    /**
     * 查询库存数量列表
     */
    @PreAuthorize("@ss.hasPermi('wms:stock:list')")
    @GetMapping("/list")
    public TableDataInfo list(WmsProductStock wmsProductStock) {
        startPage();
        List<WmsProductStock> list = wmsProductStockService.selectWmsProductStockList(wmsProductStock);
        return getDataTable(list);
    }

    /**
     * 导出库存数量列表
     */
    @PreAuthorize("@ss.hasPermi('wms:stock:export')")
    @Log(title = "库存数量", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WmsProductStock wmsProductStock) {
        List<WmsProductStock> list = wmsProductStockService.selectWmsProductStockList(wmsProductStock);
        ExcelUtil<WmsProductStock> util = new ExcelUtil<WmsProductStock>(WmsProductStock.class);
        util.exportExcel(response, list, "库存数量数据");
    }

    /**
     * 获取库存数量详细信息
     */
    @PreAuthorize("@ss.hasPermi('wms:stock:query')")
    @GetMapping(value = "/{id}")
    public PageData getInfo(@PathVariable("id") Long id) {
        return success(wmsProductStockService.selectWmsProductStockById(id));
    }

    //根据物品编码获取库存信息
    @GetMapping(value = "/product/{productCode}")
    public PageData getStockByProductCode(@PathVariable("productCode") String productCode) {
        return success(wmsProductStockService.selectWmsProductStockByProductCode(productCode));
    }

    /**
     * 新增库存数量
     */
    @PreAuthorize("@ss.hasPermi('wms:stock:add')")
    @Log(title = "库存数量", businessType = BusinessType.INSERT)
    @PostMapping
    public PageData add(@RequestBody WmsProductStock wmsProductStock) {
        return toAjax(wmsProductStockService.insertWmsProductStock(wmsProductStock));
    }

    /**
     * 修改库存数量
     */
    @PreAuthorize("@ss.hasPermi('wms:stock:edit')")
    @Log(title = "库存数量", businessType = BusinessType.UPDATE)
    @PutMapping
    public PageData edit(@RequestBody WmsProductStock wmsProductStock) {
        return toAjax(wmsProductStockService.updateWmsProductStock(wmsProductStock));
    }

    /**
     * 删除库存数量
     */
    @PreAuthorize("@ss.hasPermi('wms:stock:remove')")
    @Log(title = "库存数量", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public PageData remove(@PathVariable Long[] ids) {
        return toAjax(wmsProductStockService.deleteWmsProductStockByIds(ids));
    }
}
